#pragma once
#include <complex>
#include "datastore.h"
#include "WaitBoxHelper.h"
#include "waconsts.h"


class GSpectForm
{
private:
	CWnd *parent;
	DataStore *dataStore;
	bool viewType;//false=draw all;true=draw single
	bool isCalculating;
	int selectedChannel,currentPage;
	//std::complex<double> *in;
	std::vector<FFTOutput> out;
	std::vector<BMPBuffer> bmpBuf;

	UINT DoCalc(int ch,int start,int end);//calc the fft of the n-th ch.
	friend UINT FFT_Working_Thread( LPVOID );
	
protected:
	WaitBox wb;

public:
	GSpectForm(CWnd *h, DataStore* d):parent(h),dataStore(d),isCalculating(0),viewType(false)
		,selectedChannel(-1),currentPage(0){};
	~GSpectForm(void);
	void Draw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid);
	bool StartCalc(int ch,int start=0,int end=0);
	int CalculatedChannelCount(){return out.size();}
	void DrawBitmap(int ch,Bitmap &bmp,int w,int h);



	void SwitchView(void)
	{
		viewType=!viewType;
	}
	bool GetViewType(){return viewType;}
	int GetSelectedChannel(){return selectedChannel;}
	int selectChannel(int x, int y);
	void DrawAllOutput(Bitmap &bmp,int w,int h);
	void UpdateBitmapBuffer(void);
private:
	int FindInBuf(int ch);
	int FindInOut(int ch);
public:
	void DrawThumbnail(int ch,Bitmap *bmp,int w,int h);
	bool ExportSelected2File(LPCTSTR filename);
	void GetOutputDetailString(int ch, LPTSTR buf);
	bool SetCurrentPage(int offset);
};